<%--
  Created by IntelliJ IDEA.
  User: kkk
  Date: 2022/8/17
  Time: 9:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="${pageContext.request.contextPath}/">
    <script src="js/jquery.js"></script>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--    <style>--%>
<%--        *{--%>
<%--            background-color: dimgray;--%>
<%--            background-color: blanchedalmond;--%>
<%--        }--%>
<%--    </style>--%>
</head>
<body>
    <h2>海淀区工商局组织机构管理系统</h2>
    <form action="add.jsp">
        <input type="submit" value="添加组织机构">
    </form>
    <table border="1">
        <tr>
            <th>组织机构名称</th>
            <th>负责人</th>
            <th>业务状态</th>
            <th>创建日期</th>
            <th>操作</th>
        </tr>
        <c:forEach var="orgnazition" items="${list}">
            <tr>
                <td>${orgnazition.name}</td>
                <td>${orgnazition.principalName}</td>
                <td>${orgnazition.status==0? "开启业务":"暂停业务"}</td>
                <td>${orgnazition.createDate}</td>
                <td><a href="javascript:void(0)" onclick="checkStatus(${orgnazition.id},${orgnazition.status})" class="${orgnazition.id}">${orgnazition.status==1? "开启业务":"暂停业务"}</a></td>
            </tr>
        </c:forEach>
    </table>
    <p><%=request.getAttribute("status")%></p>
</body>
<script>
    $(function () {
        $('tr:even').css("backgroundColor","blanchedalmond");
        $('tr:first').css("backgroundColor","dimgray");
    })
    function checkStatus(id,status) {
        // 获取操作状态信息
        let msg = status==0?"暂停服务":"开启服务";
        if (confirm("确定"+msg+"吗？")){
            $.get("ChangeStatusServlet","status="+(msg==="开启服务"?0:1)+"&id="+id,function (data) {
                if (data==="true") {
                    location.href="ListServlet?status="+msg;
                    ;
                }
            })
        }
    }
</script>
</html>
